// authUtil.js
const jwt = require('jsonwebtoken');

const jwtSecret = 'a_jwt_secret';

const generateToken = (data) => {
  return jwt.sign(data, jwtSecret, { expiresIn: '1h' }); // 令牌有效期为1小时
};

const verifyToken = (token) => {
  try {
    return jwt.verify(token, jwtSecret);
  } catch (error) {
    return null;
  }
};

module.exports = {
  generateToken,
  verifyToken
};
